package com.lin.service.impl;

import com.lin.service.CaptchaService;
import com.lin.utils.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author mijiupro
 */
@Service
@Slf4j
public class CaptchaServiceImpl implements CaptchaService {
    private final SmsUtil smsUtil;

    public CaptchaServiceImpl(SmsUtil smsUtil) {
        this.smsUtil = smsUtil;
    }

    @Override
    public void getSmsCaptcha(String phone) {
        String captcha = "";
        if (StringUtils.isBlank(captcha)) {
            captcha = RandomStringUtils.randomNumeric(4);}
        // 发送短信
        if (!smsUtil.sendSms(phone, captcha)) {
            System.out.println("发送短信失败");
        }
    }
}